//
//  DataImageViewController.m
//  MaskMachine
//
//  Created by yuanyuan on 15-3-13.
//  Copyright (c) 2015年 hanjiaxue. All rights reserved.
//

#import "DataImageViewController.h"
#import "DZNSegmentedControl.h"
#import "AccountTableViewCell.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "HightLightsViewController.h"
#import "YoungAllData.h"
#import "GMDCircleLoader.h"
@interface DataImageViewController ()<YoungDelegate>
@property(nonatomic,retain)NSMutableArray *zArrayData;
@end
static NSString *aoutImageCell = @"Cell";
@implementation DataImageViewController
@synthesize zName,zCID,zArrayData;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    self.navigationController.navigationBarHidden=YES;
    self.view.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    [self initNav];
    navTitle.text = zName;

    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate = self;
    [data gainGoodsList:zCID andPageID:@"1" andPerPage:@"15" andSearch:@"" andAgentID:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"]];
    [GMDCircleLoader setOnView:self.view withTitle:@"加载中···" animated:YES];
    
}
#pragma mark - 商品列表回调
-(void)goodsList:(NSDictionary *)sign{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    zArrayData = [[NSMutableArray alloc]initWithArray:[sign objectForKey:@"data"]];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, navView.bottom, self.view.frame.size.width, self.view.frame.size.height-64-self.sege.frame.size.height-50)];
    _tableView.backgroundColor = [UIColor clearColor];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorColor = [UIColor clearColor];
    [self.view addSubview:_tableView];
    
    [_tableView registerClass:[AccountTableViewCell class] forCellReuseIdentifier:aoutImageCell];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];

    }
}
#pragma mark - 商品列表回调失败
-(void)requistFail{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma mark - 返回
-(void)clickBackBtn{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)downloadDataDetailImg:(NSArray *)array{
    
    self.array = [NSArray arrayWithArray:array];
    [self.tableView reloadData];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AccountTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:aoutImageCell];
    cell.titleLabel.text = [[zArrayData objectAtIndex:indexPath.row] objectForKey:@"ProductName"];
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [zArrayData count];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    HightLightsViewController *imgVC = [[HightLightsViewController alloc] init];
    imgVC.productStr = [[zArrayData objectAtIndex:indexPath.row] objectForKey:@"ProductID"];
    imgVC.productName = [[zArrayData objectAtIndex:indexPath.row] objectForKey:@"ProductName"];
    [self.navigationController pushViewController:imgVC animated:YES];
    
    
    
}




#pragma mark - segmentDelegate
- (UIBarPosition)positionForBar:(id <UIBarPositioning>)view
{
    return UIBarPositionBottom;
}
-(void)dealloc{
    self.tableView = nil;
    self.array = nil;
    self.sege = nil;
    self.imgURL = nil;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
